{% extends 'core/base.html' %}
{% block content %}
<div class="history-container">
    <h2>我的查询记录</h2>

    {% if history %}
        <div class="history-list">
            {% for record in history %}
                <div class="history-item">
                    <div class="history-content">
                        <div class="history-keyword">{{ record.keyword }}</div>
                        <div class="history-time">{{ record.searched_at|date:"Y-m-d H:i" }}</div>
                    </div>
                    <a href="{% url 'search' %}?q={{ record.keyword }}" class="search-again-btn">
                        再次查询
                    </a>
                </div>
            {% endfor %}
        </div>
    {% else %}
        <div class="empty-history">
            <div class="empty-icon">📝</div>
            <p>你还没有查询记录。</p>
            <a href="{% url 'search' %}?q=" class="btn">开始查询</a>
        </div>
    {% endif %}
</div>

<style>
    .history-container {
        max-width: 800px;
        margin: 0 auto;
    }

    .history-list {
        margin-top: 2rem;
    }

    .history-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: white;
        padding: 1rem 1.5rem;
        border-radius: 8px;
        margin-bottom: 1rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        transition: transform 0.2s;
    }

    .history-item:hover {
        transform: translateY(-3px);
        box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    }

    .history-content {
        flex: 1;
    }

    .history-keyword {
        font-weight: 500;
        font-size: 1.1rem;
        color: var(--primary-dark);
    }

    .history-time {
        color: var(--text-light);
        font-size: 0.9rem;
        margin-top: 0.3rem;
    }

    .search-again-btn {
        background-color: var(--secondary);
        color: white;
        padding: 8px 15px;
        border-radius: 20px;
        font-size: 0.9rem;
        text-decoration: none;
        transition: background-color 0.3s;
    }

    .search-again-btn:hover {
        background-color: #1976D2;
        text-decoration: none;
    }

    .empty-history {
        text-align: center;
        padding: 3rem 1rem;
        background-color: #f5f5f5;
        border-radius: 10px;
        margin-top: 2rem;
    }

    .empty-icon {
        font-size: 3rem;
        margin-bottom: 1rem;
    }

    .empty-history p {
        margin-bottom: 1.5rem;
        color: var(--text-light);
    }

    @media (max-width: 768px) {
        .history-item {
            flex-direction: column;
            align-items: flex-start;
        }

        .search-again-btn {
            margin-top: 1rem;
            align-self: flex-end;
        }
    }
</style>
{% endblock %}